﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SangoBang
{
    class CureAction : Action
    {
        public CureAction(Player sender, Player receiver)
            : base(sender, receiver)
        { 
        
        }

        public override string Do()
        {
            StringBuilder rtnMsg = new StringBuilder(512);

            //动作发出者 减去一个张牌
            --this.Sender.CardNumber;
            //被治愈方 加1hp
            ++this.Receiver.HP;

            rtnMsg.Append("<message type=\"playerAction\"><action type=\"cure\" player=\"");
            rtnMsg.Append(this.Sender.mName);
            rtnMsg.Append("\" target=\"");
            rtnMsg.Append(this.Receiver.mName);
            rtnMsg.Append("\"></action></message>");


            StringBuilder rtnMsg2 = new StringBuilder(512);
            rtnMsg2.Append("<message type=\"playerUpdate\"><playerStatus player=\"");
            rtnMsg2.Append(this.Receiver.mName);
            rtnMsg2.Append("\" cardNumber=\"");
            rtnMsg2.Append(this.Receiver.CardNumber);
            rtnMsg2.Append("\" life=\"");
            rtnMsg2.Append(this.Receiver.HP);
            rtnMsg2.Append("\"></playerStatus></message>");


            foreach (Player player in this.Receiver.Game.mPlayerList)
            {
                lock (player.MessageQueue)
                {
                    player.MessageQueue.Enqueue(rtnMsg.ToString());
                    player.MessageQueue.Enqueue(rtnMsg2.ToString());
                }
                player.MessageEvent.Set();
            }

            return string.Empty;
        }
    }
}
